import 'package:flutter/material.dart';

import 'package:junyeyishu/utils/utils.dart';
import 'package:junyeyishu/widgets/QGButton.dart';

class QGAlert extends StatelessWidget {
  String title;
  String content;
  String cancel;
  String confirm;
  void Function()? onCancel;
  void Function()? onConfirm;
  BuildContext context;

  QGAlert({
    super.key,
    required this.context,
    required this.title,
    required this.content,
    required this.cancel,
    required this.confirm,
    this.onCancel,
    this.onConfirm,
  });

  static show(context,
      {title = '温馨提醒',
      content = "",
      cancel = "取消",
      confirm = "确定",
      onCancel,
      onConfirm}) {
    showDialog(
        context: context,
        builder: (context) {
          return QGAlert(
              context: context,
              title: title,
              content: content,
              cancel: cancel,
              confirm: confirm,
              onCancel: onCancel,
              onConfirm: onConfirm);
        });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          margin: EdgeInsets.symmetric(horizontal: 25.rpx),
          padding: EdgeInsets.symmetric(horizontal: 20.rpx, vertical: 35.rpx),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20.rpx),
            color: Color(0xFF232A32),
          ),
          child: Column(mainAxisSize: MainAxisSize.min, children: [
            buildHeader(),
            SizedBox(height: 30.rpx),
            buildButtons(),
          ]),
        ),
      ],
    );
  }

  buildHeader() {
    return Column(
      children: [
        Text(
          title,
          style: TextStyle(
              color: Color(0xFFFFFFFF),
              fontSize: 16.rpx,
              fontWeight: FontWeight.bold),
        ),
        SizedBox(height: 25.rpx),
        Text(
          content,
          style: TextStyle(
              color: Color(0xFFFFFFFF),
              fontSize: 14.rpx,
              fontWeight: FontWeight.bold),
        ),
      ],
    );
  }

  buildButtons() {
    return SizedBox(
      height: 100.rpx,
      child: Column(
        children: [

          QGButton(
                  title: confirm,
                  enable: true,
                  onTap: () {
                    if (onConfirm != null) {
                      onConfirm!();
                    } else {
                      Navigator.of(context).pop();
                    }
                  }),
          SizedBox(width: 15.rpx),

 QGOutlineButton(
                  title: cancel,
                  enable: true,
                  onTap: () {
                    if (onCancel != null) {
                      onCancel!();
                    } else {
                      Navigator.of(context).pop();
                    }
                  })

   
          
        ],
      ),
    );
  }
}
